package com.stone.bypass.proxy.core.selector;

import com.stone.bypass.proxy.core.support.DiversionSelector;
import java.util.Map;

/**
 * @Auther: stone
 * @Description: 服务层分流选择器
 * @date Date : 2021年03月08日 2:46 下午
 */
public class ServiceProxySelector implements DiversionSelector {

  @Override
  public Object nonDivert(Map<String, Object> proxyMap) {
    Object selectObj = proxyMap.get(DiversionSelector.VERSION_EMPTY);
    if (selectObj != null) {
      return selectObj;
    }
    selectObj = proxyMap.get(VERSION_V1);
    if (selectObj != null) {
      return selectObj;
    }
    throw new RuntimeException("找不到符合条件的分流对象");
  }

  @Override
  public Object divert(String key, Map<String, Object> proxyMap) {
    Object selectObj = null;
    String version = "v1";
    // 自定义实现version筛选的逻辑
    selectObj = proxyMap.get(version);
    if (selectObj != null) {
      return selectObj;
    }
    throw new RuntimeException("找不到符合条件的分流对象");
  }
}
